<template>
  <div>
    <h5 class="titleInfo">医院评价</h5>
    <el-form label-width="130px" ref="params" :rules="rules" :model="params">
      <el-row>
        <el-col :span="24">
          <el-form-item label="医院名称" prop="hospitalId">
            <el-select filterable placeholder="请选择" @change="selectfn" v-model="params.hospitalId">
              <el-option v-for="item in list" :key="item.id" :label="item.name" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="医院评分">
            <span class="spanToInput"></span>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="医院服务" prop="hospitalServerStar">
            <div style="padding-top: 10px;">
              <el-rate v-model="params.hospitalServerStar"></el-rate>
            </div>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="医院环境" prop="hospitalEnvStar">
            <div style="padding-top: 10px;">
              <el-rate v-model="params.hospitalEnvStar"></el-rate>
            </div>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="医院关怀" prop="hospitalCareStar">
            <div style="padding-top: 10px;">
              <el-rate v-model="params.hospitalCareStar"></el-rate>
            </div>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="医院评价" prop="hospitalContents">
            <div style="padding-top: 10px;">
              <el-input
                v-model="params.hospitalContents"
                type="textarea"
                :rows="2"
                placeholder="请输入内容最大不超过300"
                :maxlength="300"
              ></el-input>
            </div>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>
<script>
const vaildateStart = (rule, value, callback) => {
  if (!value) {
    callback(new Error("不能低于一星"));
  } else {
    callback();
  }
};
export default {
  props: {
    list: {
      type: Array,
      default: []
    }
  },
  watch: {
    // params(val){
    //   console.log(val)
    //   this.$emit("childfun", this.params);
    // }
  },
  data() {
    return {
      rules: {
        hospitalId: [
          {
            required: true,
            message: "请输入医院名称",
            trigger: "blur"
          }
        ],
        hospitalContents: [
          {
            required: true,
            message: "医院评价不能为空",
            trigger: "blur"
          }
        ],
        hospitalServerStar: [
          {
            validator: vaildateStart,
            trigger: "blur"
          }
        ],
        hospitalEnvStar: [
          {
            validator: vaildateStart,
            trigger: "blur"
          }
        ],
        hospitalCareStar: [
         {
            validator: vaildateStart,
            trigger: "blur"
          }
        ]
      },
      value1: 0,
      hospitalId: null,
      params: {}
    };
  },
  methods: {
    checkfn() {
      let abc = "";
      this.$refs["params"].validate(valid => {
        console.log(123, valid);

        if (valid) {
          abc = true;
        } else {
          this.$message({
            message: "请完善信息再提交",
            type: "warning"
          });
          abc = false;
        }
      });
      return abc;
    },
    selectfn(val) {
      // console.log(val,this.list)
      let arr = this.list.filter(res => {
        return res.id == val;
      });
      // console.log(arr)
      //  this.params = arr[0];
      // this.params.hospitalId = val;
      this.params.hospitalName = arr[0].name;
      this.$emit("childfun", this.params);
    }
  }
};
</script>
